package com.dong.es.config;

import org.apache.commons.pool2.PooledObjectFactory;
import org.apache.commons.pool2.impl.AbandonedConfig;
import org.apache.commons.pool2.impl.GenericObjectPool;
import org.apache.commons.pool2.impl.GenericObjectPoolConfig;

/**
 * @description:
 * @author: 陈瑞东
 * @create: 2022-06-08 10:14
 */
public class EsClientPool extends GenericObjectPool<EsClient> {

    /**
     * 获得对象
     *
     * @return
     * @throws Exception
     */
    public EsClient getClient() throws Exception {
        // 从池中取一个对象
        EsClient client = borrowObject();
        return client;
    }

    /**
     * 归还对象
     *
     * @param client
     */
    public void returnClient(EsClient client) {
        // 使用完毕之后，归还对象
        if (client != null) {
            returnObject(client);
        }
    }

    public EsClientPool(PooledObjectFactory<EsClient> factory) {
        super(factory);
    }

    public EsClientPool(PooledObjectFactory<EsClient> factory, GenericObjectPoolConfig<EsClient> config) {
        super(factory, config);
    }

    public EsClientPool(PooledObjectFactory<EsClient> factory, GenericObjectPoolConfig<EsClient> config, AbandonedConfig abandonedConfig) {
        super(factory, config, abandonedConfig);
    }
}
